CMAKE_MINIMUM_REQUIRED(VERSION 3.17)

IF (CMAKE_SYSTEM MATCHES "Linux")
    IF (NOT TARGET LINUX::H)
        SET(LINUX_H_PARAMS -fPIC -Wall -Werror -Wno-format-security)
        ADD_LIBRARY(LINUX::H INTERFACE IMPORTED)
        TARGET_COMPILE_OPTIONS(LINUX::H INTERFACE "${LINUX_H_PARAMS}")
    ENDIF ()

    IF (NOT TARGET LINUX::Z)
        FIND_LIBRARY(LINUX_Z NAMES z)
        ADD_LIBRARY(LINUX::Z SHARED IMPORTED)
        SET_TARGET_PROPERTIES(LINUX::Z PROPERTIES IMPORTED_LOCATION "${LINUX_Z}")
    ENDIF ()

    IF (NOT TARGET LINUX::DL)
        FIND_LIBRARY(LINUX_DL NAMES dl)
        ADD_LIBRARY(LINUX::DL SHARED IMPORTED)
        SET_TARGET_PROPERTIES(LINUX::DL PROPERTIES IMPORTED_LOCATION "${LINUX_DL}")
    ENDIF ()

    IF (NOT TARGET LINUX::PTHREAD)
        FIND_LIBRARY(LINUX_PTHREAD NAMES pthread)
        ADD_LIBRARY(LINUX::PTHREAD SHARED IMPORTED)
        SET_TARGET_PROPERTIES(LINUX::PTHREAD PROPERTIES IMPORTED_LOCATION "${LINUX_PTHREAD}")
    ENDIF ()
ENDIF ()

IF (NOT TARGET LIBRARIES::LINUX)
    ADD_LIBRARY(LIBRARIES::LINUX INTERFACE IMPORTED GLOBAL)
    TARGET_LINK_LIBRARIES(LIBRARIES::LINUX INTERFACE
            LINUX::H
            LINUX::Z
            LINUX::DL
            LINUX::PTHREAD)
ENDIF ()